@extends('layouts.console_main')

@section('resources')
    @parent
    <style type="text/css">
        tbody a{padding-right: 20px;}
        #close{  width:40%;  height:400px;  cursor:pointer;  position:absolute;  right:40%;  top:20%;  background: aqua;  padding:1px;}
    </style>
@endsection

@section('content')

<div class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h2>水表管理  >> 水表列表 </h2>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="row">
            @foreach($lists as $list)
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>  {{$list['enterprise_name']}}   </h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                <ul class="dropdown-menu" role="menu">
                                    {{--<li><a href="#">Settings 1</a>--}}
                                    {{--</li>--}}
                                    {{--<li><a href="#">Settings 2</a>--}}
                                    {{--</li>--}}
                                </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>

                    <div class="x_content">
                        {{--<p class="text-muted font-13 m-b-30">--}}
                        {{--DataTables has most features enabled by default, so all you need to do to use it with your own tables is to call the construction function: <code>$().DataTable();</code>--}}
                        {{--</p>--}}
                        <table id="datatable" class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>名称</th>
                                <th>计量区域</th>
                                <th>底数</th>
                                <th>检测状态</th>
                                <th>上报检测时间</th>
                                <td>检测周期</td>
                                <th>节点等级</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($list['child_lists'] as $child_list)
                                <tr>
                                    <td><a href="/water/get?id={{$child_list['id']}}">{{$child_list['number']}}</a></td>
                                    <td>{{$child_list['name']}}</td>
                                    <td>{{$child_list['area']}}</td>
                                    <td>{{$child_list['radix']}} &nbsp;<i class="fa fa-edit" onclick="write_radix('{{$child_list['number']}}', '{{$child_list['name']}}')"></i></td>
                                    <td><?php echo ($child_list['status'] == '1')? "已检测":"未检测";?> &nbsp;<i class="fa fa-edit" onclick="revise_status('{{$child_list['number']}}', '{{$child_list['name']}}')"></i></td>
                                    @if($child_list['check_time'] == '')
                                    <td>--</td>
                                    @else
                                    <td>{{date('Y-m-d H:i:s', strtotime($child_list['check_time']))}}</td>
                                    @endif
                                    <td>{{$child_list['period']}}天</td>
                                    @if($child_list['node_level'] == 1)
                                        <td style="background-color:deepskyblue;">{{$child_list['node_level']}}</td>
                                    @elseif($child_list['node_level'] == 2)
                                        <td style="background-color: #1ABB9C">{{$child_list['node_level']}}</td>
                                    @else
                                        <td>{{$child_list['node_level']}}</td>
                                    @endif
                                    <td>
                                        <a href="/water/get?id={{$child_list['id']}}"><i class="fa fa-edit"></i></a>
                                        <a href="/water/statistic/get?id={{$child_list['id']}}"><i class="fa fa-bar-chart-o"></i></a>
                                        @if($child_list['is_father'])
                                            <a href="/water/child_node/get?id={{$child_list['id']}}"><i class="fa fa-sitemap"></i></a>
                                        @endif
                                        <a href="/water/qrcode/download?id={{$child_list['id']}}"><i class="fa fa-qrcode"></i></a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        {{--<div id="close">点击关闭</div>--}}
                    </div>
                </div>
            </div>
            <br />
            <div class="clearfix"></div>
         @endforeach
        </div>

        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>  其他医院 </h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                <ul class="dropdown-menu" role="menu">
                                    {{--<li><a href="#">Settings 1</a>--}}
                                    {{--</li>--}}
                                    {{--<li><a href="#">Settings 2</a>--}}
                                    {{--</li>--}}
                                </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>

                    <div class="x_content">
                        {{--<p class="text-muted font-13 m-b-30">--}}
                        {{--DataTables has most features enabled by default, so all you need to do to use it with your own tables is to call the construction function: <code>$().DataTable();</code>--}}
                        {{--</p>--}}
                        <table id="datatable" class="table table-striped table-bordered">
                            <thead>

                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <br />
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<!--  修改底数 -->
<div style="position:absolute; left: 600px; top:350px; width: 450px; height: 200px;" id="write_radix" hidden>
    <div class="col-md-12 col-sm-6 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2 id="write_radix_name"></h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li><a class="close-link" id="close_write_radix"><i class="fa fa-close"></i></a></li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form class="form-horizontal form-label-left">
                    <div class="form-group">
                        <label class="col-sm-3 control-label"> 编号：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="write_radix_number" readonly class="form-control col-md-7 col-xs-12" name="write_radix_number" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">底数：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="write_radix_radix" required="required" class="form-control col-md-7 col-xs-12" name="write_radix_radix">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">时间：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="date" id="write_radix_date" required="required" class="form-control col-md-7 col-xs-12" name="write_radix_date">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-1">
                            <button class="btn btn-primary" type="button" id="write_radix_submit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--  修改检测状态 -->
<div style="position:absolute; left: 600px; top:350px; width: 450px; height: 200px;" id="revise_status" hidden>
    <div class="col-md-12 col-sm-6 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2 id="revise_status_name"></h2>
                <ul class="nav navbar-right panel_toolbox">
                    <li><a class="close-link" id="close_write_radix"><i class="fa fa-close"></i></a></li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <form class="form-horizontal form-label-left">
                    <div class="form-group">
                        <label class="col-sm-3 control-label"> 编号：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="revise_status_number" readonly class="form-control col-md-7 col-xs-12" name="revise_status_number" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <select id="heard" class="form-control" required name="revise_status_status">
                                <option value="0">未检测</option>
                                <option value="1">已检测</option>
                                <option value="2">已坏</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"> 时间：</label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="date" id="revise_status_date" class="form-control col-md-7 col-xs-12" name="revise_status_date" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-1">
                            <button class="btn btn-primary" type="button" id="revise_status_submit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scriptResources')
    @parent
    <script>
        function write_radix(number, name) {
            $("#write_radix").show();
            $("#write_radix_name").html(name);
            $("input[name='write_radix_number']").val(number);
            console.log("number:"+number);
        }
        function revise_status(number, name) {
            $("#revise_status").show();
            $("#revise_status_name").html(name);
            $("input[name='revise_status_number']").val(number);
            console.log("number:"+number);
        }
        $("#write_radix_submit").click(function() {
            var write_radix_number = $("input[name='write_radix_number']").val();
            var write_radix_radix = $("input[name='write_radix_radix']").val();
            var write_radix_name = $("#write_radix_name").html();
            var write_radix_date = $("input[name='write_radix_date']").val();
            $.ajax({
                url : '/water/radix/edit',
                data: {
                    'number' : write_radix_number,
                    'name' : write_radix_name,
                    'radix': write_radix_radix,
                    'date' : write_radix_date
                },
                type:'post',
                dataType:'json',
                success:function(data){
                    if(data.status == 'failed') {
                        alert(data.message); return;
                    } else {
                        alert(data.message);
                        window.location.reload();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
        });
        $("#revise_status_submit").click(function() {
            var revise_status_number = $("input[name='revise_status_number']").val();
            var revise_status_name = $("#revise_status_name").html();
            var revise_status_status = $("select[name='revise_status_status']").find("option:selected").val();
            var revise_status_date = $("input[name='revise_status_date']").val();
            $.ajax({
                url : '/water/status/edit',
                data: {
                    'number' : revise_status_number,
                    'name' : revise_status_name,
                    'status': revise_status_status,
                    'date' : revise_status_date
                },
                type:'post',
                dataType:'json',
                success:function(data){
                    if(data.status == 'failed') {
                        alert(data.message); return;
                    } else {
                        alert(data.message);
                        window.location.reload();
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
        });
    </script>
@endsection